package day5;

import java.util.Arrays;
import java.util.Scanner;

public class Demo6 {
    public static void main(String[] args) {
        char c[]={'a','c','u','b','e','p','f','z'};
        System.out.println("排序前："+ Arrays.toString(c));
        Arrays.sort(c);
        System.out.println("排序后："+ Arrays.toString(c));
        Scanner sc=new Scanner(System.in);
        System.out.print("待插入的字符：");

        String b=sc.next();
        char ch=b.charAt(0);

        char newc[]=Arrays.copyOf(c,c.length+1);
        int index=newc.length-1;
        for (int i=0;i<c.length;i++){
            if (ch<c[i]){
                index=i;
                break;
            }
        }
        for (int i=newc.length-1;i>index;i--){
            newc[i]=newc[i-1];
        }
        //给指定的位置插入数组元素
        newc[index]=ch;
        System.out.println("查到了该元素，下标："+index);
        System.out.println("插入后："+Arrays.toString(newc));
    }

}
